package ustc.xiaoyang.service.impl;

import org.springframework.stereotype.Service;
import ustc.xiaoyang.mapper.EmpMapper;
import ustc.xiaoyang.mapper.StudentMapper;
import ustc.xiaoyang.pojo.dto.EmpJobDataDTO;
import ustc.xiaoyang.pojo.dto.StudentClazzDTO;
import ustc.xiaoyang.service.ReportService;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {
    private final EmpMapper empMapper;
    private final StudentMapper studentMapper;
    public ReportServiceImpl(EmpMapper empMapper, StudentMapper studentMapper) {
        this.empMapper = empMapper;
        this.studentMapper = studentMapper;
    }

    @Override
    public EmpJobDataDTO getEmpJobData() {
        List<Map<String, Object>> empJobData = empMapper.getEmpJobData();
        List<Object> jobList = empJobData.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = empJobData.stream().map(map -> map.get("total")).toList();
        return new EmpJobDataDTO(jobList, dataList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.getEmpGenderData();
    }

    @Override
    public StudentClazzDTO getStudentClazzData() {
        List<Map<String, Object>> studentClazzData = studentMapper.getStudentClazzData();
        List<Object> clazzName = studentClazzData.stream().map(map -> map.get("clazzName")).toList();
        List<Object> total = studentClazzData.stream().map(map -> map.get("total")).toList();
        return new StudentClazzDTO(clazzName, total);
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.getStudentDegreeData();
    }
}
